<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import = "java.sql.*, java.util.*" %>
<% request.setCharacterEncoding("euc-kr"); %>
<%
int  num=Integer.parseInt(request.getParameter("num"));
	String name = request.getParameter("name");
	String pass = request.getParameter("pass");
	String email = request.getParameter("email");
	String title = request.getParameter("title");
	String contents = request.getParameter("contents");
	
	Class.forName("com.mysql.jdbc.Driver");
	
	
	Connection conn=null;
	PreparedStatement pstmt1=null,  pstmt2=null;
	
	
		String jdbcDriver = "jdbc:mysql://192.168.0.120:3306/coffee?"
				+ "useUnicode=true&characterEncoding=euckr";
		String dbUser="root";
		String dbPass="123456";
		conn = DriverManager.getConnection(jdbcDriver, dbUser, dbPass);

		Calendar dateIn = Calendar.getInstance();
		String indate = Integer.toString(dateIn.get(Calendar.YEAR))+ "-";
		indate = indate + Integer.toString(dateIn.get(Calendar.MONTH)+1) + "-";
		indate = indate + Integer.toString(dateIn.get(Calendar.DATE)) + " ";
		
		String strSQL="update RVboard set num=num+1 where num= "+ num +" or num>"+num;
		pstmt1=conn.prepareStatement(strSQL);
		pstmt1.executeUpdate();


		 strSQL ="insert into RVboard(num,name, pass, email, title, contents, writedate, readcount)";
		strSQL = strSQL + "values(?,?,?,?,?,?,?,?)";
		
		pstmt2 = conn.prepareStatement(strSQL);
		
		pstmt2.setInt(1, num);
		pstmt2.setString(2, name);
		pstmt2.setString(3, pass);
		pstmt2.setString(4, email);
		pstmt2.setString(5, title);
		pstmt2.setString(6, contents);
		pstmt2.setString(7, indate);
		pstmt2.setInt(8, 0);
		pstmt2.executeUpdate();

		pstmt1.close();
		pstmt2.close();
		conn.close();
		
		response.sendRedirect("listboard.jsp");
		

		
	
	
%>
